package com.yunyi.web.controller.qiao;

import com.yunyi.common.core.controller.BaseController;
import com.yunyi.common.core.domain.AjaxResult;
import com.yunyi.common.core.page.TableDataInfo;
import com.yunyi.system.domain.TempType;
import com.yunyi.system.service.TempTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static java.time.LocalDateTime.now;

/**
 * @Author stephen
 * @Date 2023/8/30 10:47
 * @ClassName: TemplateTypeController
 * @Description: TODO
 * @Version 1.0
 */
@Api(tags = "模板类型控制")
@RestController
@RequestMapping("/qiao/temptype")
public class TemplateTypeController extends BaseController {

    @Autowired
    private TempTypeService tempTypeService;


    @ApiOperation(value = "分页条件查询模板信息")
    @GetMapping("/list")
    public TableDataInfo selectTTypeQuery( TempType tempType){
        startPage();
        return getDataTable(tempTypeService.selectTTypeQuery(tempType));
    }

    @ApiOperation(value = "查询模板类型详细信息")
    @GetMapping("/{tid}")
    public AjaxResult selectTypeId(@PathVariable Long tid){
        return success(tempTypeService.selectTTYpeById(tid));
    }

    @ApiOperation(value = "新增模板类型信息")
    @PostMapping
    public AjaxResult insertTType(@Validated @RequestBody(required = false) TempType tempType){
        tempType.setCreateBy(getUsername());
        return success(tempTypeService.insertType(tempType));
    }

    @ApiOperation(value = "修改模板类型信息")
    @PutMapping
    public AjaxResult updateTType(@Validated @RequestBody TempType tempType){
        System.out.println(tempType);
        tempType.setUpdateBy(getUsername());
        return success(tempTypeService.updateTType(tempType));
    }


    @ApiOperation(value = "删除操作/批量删除加,分隔")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteTTypeIds(@PathVariable("ids") Long[] ids){

        tempTypeService.deleteTTypeByIds(ids);
        return  success();
    }
}
